package org.chnxi.study.datastructrues.stack;

import java.util.Scanner;

public class ListStackTest {
    public static void main(String[] args) {
        ListStack<Integer> stack = new ListStack<>();

        String key = "";
        boolean loop = true;
        Scanner scanner = new Scanner(System.in);
        while(loop){
            System.out.println("show:显示栈");
            System.out.println("exit:退出程序");
            System.out.println("push:添加数据到栈");
            System.out.println("pop:从栈取出数据");
            System.out.println("请输入选择：");
            key = scanner.next();
            switch (key){
                case "show":
                    stack.print();
                    break;
                case "push":
                    System.out.println("请输入一个数：");
                    int val = scanner.nextInt();
                    stack.push(val);
                    break;
                case "pop":
                    try{
                        int res = stack.pop();
                        System.out.println("取出的数据："+res);
                    }catch(Exception e){
                        System.out.println("发生错误："+e.getMessage());
                    }
                    break;
                case "exit":
                    scanner.close();
                    loop = false;
                    break;
                default:
                    break;
            }
        }
        System.out.println("程序退出");
    }
}
